#******************************************************************
#
# Copyright 2016 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

##
# Notification Unit Test build script
##

from tools.scons.RunTest import run_test
Import('env')

gtest_env = SConscript('#extlibs/gtest/SConscript')
lib_env = gtest_env.Clone()

if lib_env.get('RELEASE'):
    lib_env.AppendUnique(CCFLAGS = ['-Os'])
else:
    lib_env.AppendUnique(CCFLAGS = ['-g'])

######################################################################
#unit test setting
######################################################################
easysetup_test_env = lib_env.Clone()
target_os = env.get('TARGET_OS')

######################################################################
# Build flags
######################################################################

easysetup_test_env.PrependUnique(LIBS=[
    'connectivity_abstraction',
    'oc',
    'octbstack',
    'oc_logger',
    'coap',
])

if target_os not in ['windows', 'winrt']:
    easysetup_test_env.AppendUnique(
        CXXFLAGS=['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])

easysetup_test_env.AddPthreadIfNeeded()
easysetup_test_env.PrependUnique(CPPPATH=[
    '#/extlibs/hippomocks/hippomocks',
    '#/resource/c_common',
    '#/resource/c_common/ocrandom/include',
    '#/resource/c_common/oic_malloc/include',
    '#/resource/c_common/oic_string/include',
    '#/resource/csdk/include',
    '#/resource/csdk/connectivity/api',
    '#/resource/csdk/stack/include',
    '#/resource/include',
    '#/resource/oc_logger/include',
    '#/service/easy-setup/inc',
    '#/service/easy-setup/enrollee/inc',
    '#/service/easy-setup/mediator/richsdk/inc'
])

if env.get('SECURED') == '1':
    if env.get('WITH_TCP') == True:
        easysetup_test_env.AppendUnique(
            LIBS=['mbedtls', 'mbedx509', 'mbedcrypto'])
######################################################################
# Build Test
######################################################################

easysetup_mediator_test_env = easysetup_test_env.Clone()
easysetup_mediator_test_env.AppendUnique(
    LIBS=['ESEnrolleeSDK', 'ESMediatorRich'])

src_files = ['ESMediatorTest.cpp']
easysetup_mediator_test = easysetup_mediator_test_env.Program(
    'easysetup_mediator_test', src_files)
Alias("easysetup_mediator_test", easysetup_mediator_test)
easysetup_mediator_test_env.AppendTarget('easysetup_mediator_test')

if env.get('TEST') == '1':
    if target_os in ['linux'] and env.get('SECURED') != '1':
        run_test(
            easysetup_mediator_test_env,
            # 'service_easy-setup_mediator_richsdk_unittests_easysetup_mediator_test.memcheck',
            '',  # TODO: fix this test and enable previous line
            'service/easy-setup/mediator/richsdk/unittests/easysetup_mediator_test',
            easysetup_mediator_test)

easysetup_mediator_test_env.UserInstallTargetExtra([easysetup_mediator_test],
                                               'tests/service/easy-setup/mediator/richsdk/')
